extends "../cTDA/cTDA.gd"
func _info():
	pass

func _connect():
	._connect()

func _extInit():
	._extInit()
	chaName = "忍者"
	lv = 2
	attCoe.atk = 24 / 8.5 * 2 / 2
	attCoe.maxHp = 625 / 112.5 / 2

	var cd1 = 6
	if sys.test:cd1 = 1
	addCdSkill("rz",cd1)
	addSkillTxt("分身自爆：在距离自身最远的队友周围召唤一个分身[继承25%属性，攻击为0],分身嘲讽其9宫格内敌人，3s后自爆对9宫格范围内敌人造成剩余血量真伤[cd:6秒]")

func _castCdSkill(id):
	._castCdSkill(id)
	if id == "rz":
		cst("分身自爆","000000",position)
		var chas = getAllChas(2)
		chas.sort_custom(self,"sortbydis")
		var ncha = newChara(self.id,chas[0].cell)
		if ncha != null:
			ncha.addBuff(BF1.new(1,self))
			var vs = [Vector2(0,0),Vector2(1,0),Vector2(-1,0),Vector2(0,1),Vector2(0,-1),Vector2(1,1),Vector2(-1,1),Vector2(-1,-1),Vector2(1,-1)]
			var c = ncha.cell
			for i in vs:
				if sys.main.isMatin(i + c):
					var cha = matCha(i + c)
					if !cha:continue
					if cha.get("team") != self.team:
						cha.aiCha = ncha
			if self.id != "cTDA_4":
				self.addBuff(skill_buff.new(1))

func sortbydis(a,b):
	return dis(a.cell,cell) > dis(b.cell,cell)

			
class skill_buff:
	extends Buff
	var canremove:bool = false
	func _init(lv):
		attInit()
		id = "skill_buff"
		att.atkL = 0.18
		att.maxHpL = 0.1

class BF1:
	extends Buff
	var cha
	var cnt = 0
	func _init(lv = 1,cha = null):
		attInit()
		self.cha = cha

	func _connect():
		#yield(sys.get_tree().create_timer(0.01),"timeout")
		masCha.attInfo.atk = 0
		masCha.attInfo.mgiAtk = 0
		masCha.attInfo.def = cha.attInfo.def * 0.25
		masCha.attInfo.mgiDef = cha.attInfo.mgiDef * 0.25
		masCha.attInfo.spd = cha.attInfo.spd * 0.25
		masCha.attInfo.suck = cha.attInfo.suck * 0.25
		masCha.attInfo.mgiSuck = cha.attInfo.mgiSuck * 0.25
		masCha.attInfo.cd = cha.attInfo.cd* 0.25
		masCha.attInfo.dod = cha.attInfo.dod * 0.25
		masCha.attInfo.cri = cha.attInfo.cri * 0.25
		masCha.attInfo.atkR = cha.attInfo.atkR * 0.25
		masCha.attInfo.defR = cha.attInfo.defR * 0.25
		masCha.attInfo.criR = cha.attInfo.criR * 0.25
		masCha.attInfo.pen = cha.attInfo.pen * 0.25
		masCha.attInfo.maxHp = cha.attInfo.maxHp * 0.25
		masCha.attInfo.mgiPen = cha.attInfo.mgiPen * 0.25
		masCha.isSumm = true
		masCha.upAtt()
	
	func _upS():
		cnt += 1
		if cnt == 3:
			cnt = 0
			var vs = [Vector2(1,0),Vector2(-1,0),Vector2(0,1),Vector2(0,-1),Vector2(1,1),Vector2(-1,1),Vector2(-1,-1),Vector2(1,-1)]
			var c = masCha.cell
			for i in vs:
				if sys.main.isMatin(i + c):
					var cha = masCha.matCha(i + c)
					if !cha:continue
					if cha.get("team") != masCha.team:
						masCha.hurtChara(cha,masCha.att.hp,Chara.HurtType.REAL,Chara.AtkType.SKILL)
			sys.main.delMatChara(masCha)